package com.woniuxy.credit_loans.accounting_shi.controller;

import com.woniuxy.credit_loans.accounting_shi.service.RepaymentService;
import com.woniuxy.credit_loans.entity.Repayment;
import com.woniuxy.credit_loans.entity.User;
import com.woniuxy.credit_loans.mapper.RepaymentMapper;
import com.woniuxy.credit_loans.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/repays")
public class RepaymentController {
    @Autowired
    private RepaymentService repaymentService;
    @PostMapping("/all")
    public Result r1(){
        String name=null;
        List<Repayment> list = repaymentService.selectAll("未通过",name);
        return Result.ok().data("list",list);
    }
    @PostMapping("/user")
    public Result u1(@RequestBody User user){
        List<Repayment> list = repaymentService.selectAll("未还款",user.getUserName().trim());
        return Result.ok().data("list",list);
    }
    @GetMapping("/sel/{id}")
    public Result r2(@PathVariable Long id){
        Repayment repayment = repaymentService.selectById(id);
        return Result.ok();
    }
    @GetMapping("/sell/{id}")
    public Result r4(@PathVariable Long id){
        Repayment repayment = repaymentService.selectByPrimaryKey(id);
        Integer r=repayment.getSumExpirse()-repayment.getNowExpirse();
        List<Integer> list=new ArrayList<Integer>();
        for (int i=1;i<=r;i++){
            list.add(i);
        }
        return Result.ok().data("repay",repayment).data("dang",list);
    }
    @PutMapping("")
    public Result r3(@RequestBody Repayment repayment){
        int i = repaymentService.updateByPrimaryKeySelective(repayment);
        return Result.ok();
    }
}
